﻿using System;
using System.Threading.Tasks;

using RedLockNet;

namespace Jack.RedisLib
{
    public interface IMultiRedisLock : IDisposable, IAsyncDisposable
    {
        /// <summary>
        /// 获取锁成功
        /// </summary>
        bool IsAcquired { get; }
        /// <summary>
        /// 添加红锁（锁定资源重复时，会返回空）
        /// </summary>
        /// <param name="resource">锁定的资源标识</param>
        /// <param name="expireTime">锁的过期时间（防止锁未释放，导致死锁）</param>
        /// <returns>红锁</returns>
        Task<IRedLock> AddLockAsync(string resource, TimeSpan expireTime);
        /// <summary>
        /// 创建红锁（不加实例前缀；锁定资源重复时，会返回空）
        /// </summary>
        /// <param name="resource">锁定的资源标识</param>
        /// <param name="expireTime">锁的过期时间（防止锁未释放，导致死锁）</param>
        /// <returns>红锁</returns>
        Task<IRedLock> AddLockWithoutPrefixAsync(string resource, TimeSpan expireTime);
    }
}
